﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SHNOPData.SHNOPModel;
using SHNOPData.common;

namespace SHNOPData.ExportExcel
{
    public class ExportExcelFactory
    {
        public ExportExcelFactory()
        {

        }
        public bool ExportHistoryInfo(string company, string _2gGuiHuaId, string tdGuiHuaId, string type, DataSet ds)
        {
            AbsExportExcel export = null;
            DataTable dt = null;
            switch (type)
            {
                case "0":
                    export = new ExportZhanDian();
                    dt = ds.Tables["table"];
                    break;
                case "1":
                    export = new ExportPort();
                    dt = ds.Tables["table1"];
                    break;
                case "2":
                    export = new ExportPinLv();
                    dt = ds.Tables["table2"];
                    break;
                case "3":
                    export = new ExportInNet();
                    dt = ds.Tables["table3"];
                    break;
                default:
                    break;
            }
            export._2gGuiHuaId = _2gGuiHuaId == "null" ? "" : _2gGuiHuaId;
            export.tdGuiHuaId = tdGuiHuaId == "null" ? "" : tdGuiHuaId; 
            export.company = company == "null" ? "" : company; 
           return  export.Export(dt);
         
        }
        public bool ExportNtPlanInfo(string type)
        {
            NTPlanSearchItem nTPlanSearchItem = new NTPlanSearchItem();
            string fileName = "规划站点信息.xls";
            ///导出所有数据
            if (type.Equals("all"))
            {
                nTPlanSearchItem.Sim_SearchContent = "";
                nTPlanSearchItem.Sim_SearchType = "0";
                nTPlanSearchItem.Sim_CompanyIDS = "";
            }
            ///按查询条件导出查询的数据
            else if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Session["searchItem"] != null)
            {
                nTPlanSearchItem = (NTPlanSearchItem)System.Web.HttpContext.Current.Session["searchItem"];
            }
            ///查询条件session失效，查全部（或增加功能提示客户端重新查询）
            else
            {
                nTPlanSearchItem.Sim_SearchContent = "";
                nTPlanSearchItem.Sim_SearchType = "0";
                nTPlanSearchItem.Sim_CompanyIDS = "";
            }
            DataTable dt=  AppDBMng.ExportPlanExcel(nTPlanSearchItem);
            if (dt!=null)
            {
                return HelperClass.ExcelHelper.ExportToExcelFromTable(dt, fileName);
            }
            return false;
        }
    }
}
